package com.smart.cosstarter.config;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.model.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: jj
 * @Date: 2019/8/6 16:56
 * @Version 1.0
 */
public class COSBucketsManager {

	private COSClient cosClient;

	public COSBucketsManager(COSClient cosClient) {
		this.cosClient = cosClient;
	}

	public List<Bucket> listBuckets() throws CosClientException {
		return cosClient.listBuckets();
	}

	public Bucket createBucket(String bucketName) throws CosClientException {
		return cosClient.createBucket(bucketName);
	}

	public boolean doesBucketExist(String bucketName) throws CosClientException {
		return cosClient.doesBucketExist(bucketName);
	}

	public void deleteBucket(String bucketName) throws CosClientException {
		cosClient.deleteBucket(bucketName);
	}

	// 方法 1 (设置自定义策略)
	public void setBucketAcl(String bucketName, AccessControlList acl) throws CosClientException {
		cosClient.setBucketAcl(bucketName, acl);
	}

	// 方法 2 (设置预定义策略)
	public void setBucketAcl(String bucketName, CannedAccessControlList acl) throws CosClientException {
		cosClient.setBucketAcl(bucketName, acl);
	}

	// 方法 3 (以上两种方法的封装, 包含两种策略设置，如果同时设置以自定定义策略为主)
	public void setBucketAcl(SetBucketAclRequest setBucketAclRequest) throws CosClientException {
		cosClient.setBucketAcl(setBucketAclRequest);
	}

	//	查询指定存储桶的访问权限控制列表。
	public AccessControlList getBucketAcl(String bucketName) throws CosClientException{
		return cosClient.getBucketAcl(bucketName);
	}
}
